package fr.cephb.locustree.admin;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import javax.xml.XMLConstants;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;

import org.xml.sax.SAXException;

import fr.cephb.util.AbstractCmdLine;

public class AbstractLocusTreeCmd
	extends AbstractCmdLine
	{
	private File dbHome=null;
	
	protected enum REPLACE_POLICY
		{
		IGNORE,
		UPDATE,
		ERROR
		};
	
	protected AbstractLocusTreeCmd()
		{
		
		}
	
	protected File getDbHome()
		{
		return dbHome;
		}
	
	@Override
	protected int processArg(String[] args, int optind)
		{
		if(args[optind].equals("-db-home"))
			{
			this.dbHome= new File(args[++optind]);
			return optind;
			}
		return super.processArg(args, optind);
		}
	
	protected Schema loadSchema(String schemaLoc) throws IOException,SAXException
		{
		SchemaFactory factory=SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
		InputStream schemaIn= getClass().getClassLoader().getResourceAsStream(schemaLoc);
		if(schemaIn==null) throw new FileNotFoundException("Cannot find ");
		Schema schema= factory.newSchema(new StreamSource(schemaIn));
		schemaIn.close();
		return schema;
		}
	}
